<?php

/**
 * 节点管理
 * @author  Mr.L <349865361@qq.com>
 */

namespace app\topics\admin;

class NodeAdmin extends \app\system\admin\SystemExtendAdmin {

    protected $_model = 'TopicsNode';

    /**
     * 模块信息
     */
    protected function _infoModule() {
        return [
            'info' => [
                'name' => '节点管理',
                'description' => '管理论坛节点',
                'url' => url('system/User/index'),
            ],
            'fun' => [
                'index' => true,
                'add' => true,
                'edit' => true,
                'del' => true,
                'status' => true,
            ]
        ];
    }

    public function _indexParam() {
        return [
            'group_id' => 'A.group_id',
            'keyword' => 'A.name'
        ];
    }


    protected function _indexAssign($pageMaps) {
        return array(
            'groupList' => target('topics/TopicsNodeGroup')->loadList(),
            'groupId' => $pageMaps['group_id']
        );
    }

    protected function _addAssign() {
        return array(
            'groupList' => target('topics/TopicsNodeGroup')->loadList(),
            'roleList' => target('topics/TopicsUserRole')->loadList(),
            'typeList' => target('topics/Topics', 'service')->getTypeAll(),
            'postRole' => [],
            'userList' => []
        );
    }

    protected function _editAssign($info) {
        $userList = [];
        if ($info['moderator']) {
            $userList = target('member/MemberUser')->loadList(['_sql' => 'user_id in(' . $info['moderator'] . ')']);
        }
        return array(
            'groupList' => target('topics/TopicsNodeGroup')->loadList(),
            'roleList' => target('topics/TopicsUserRole')->loadList(),
            'postRole' => explode(',', $info['post_role']),
            'userList' => $userList
        );
    }

    protected function _delBefore($id) {
        if ($id == 1) {
            $this->error('保留节点无法删除！');
        }
    }

}